<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="toPay()">点击支付</button>

    <script>
        function toPay() {
            let info = {
    "timeStamp": "1629374277",
    "package": "prepay_id=wx191957581819259193c8d0a287e16c0000",
    "paySign": "AC0DA09C251928588B03BA6FB4D1CAA4BE54D6F896D930544D97422A81891A11",
    "appId": "wxa44359c5ebfba07f",
    "signType": "HMAC-SHA256",
    "nonceStr": "1629374277642"
  }

            wxPay(info).then(res => {
                alert('ok')
            }).catch(err => {
                console.log('err', err)
                alert(JSON.stringify(err))
            })
        };

        // 使用微信支付
        function wxPay(info) {
            return new Promise((resolve, reject) => {
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', info,
                    function (res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            console.log('支付完成')
                            resolve()
                        } else {
                            reject('支付失败');
                        }
                    });
            })
        }
    </script>
</body>

</html>